import java.sql.*;


public class Test {
    public static void main(String[] args) {
        try{
            //加载JDBC驱动程序:反射,这样调用初始化com.mysql.jdbc.Driver类,即将该类加载到JVM方法区,
            //并执行该类的静态方法块,静态属性.
            Class.forName("com.mysql.cj.jdbc.Driver");

            //创建数据库连接
            Connection connection =
                    DriverManager.getConnection("jdbc:mysql://localhost:3306/bit32mall?" +
                            "user=root&password=root&useUnicode=true&characterEncoding=utf-8");
            //创建操作命令(Statement)
            Statement statement = (Statement) connection.createStatement();

            //执行SQl语句
            ResultSet set=statement.executeQuery("update goods set price=40 where where id=1");
        }catch (ClassNotFoundException e){
            throw new RuntimeException();
        }catch (SQLException e){
            throw new RuntimeException();
        }
//        //注册驱动
//        Class.forName("com.mysql.jdbc.Driver");
//        //获取连接
//        String url="jdbc:mysql://127.0.0.1:3306/bit32mall";
//        String username="root";
//        String password="123qwe...";
//        Connection conn= DriverManager.getConnection(url,username,password);
//        //定义sql语句
//        String sql="update goods set price=40 where where id=1";
//        //获取sql对象
//        Statement set= conn.createStatement();
//        //执行sql
//        int count=set.executeUpdate(sql);
//        System.out.println(count);
//        set.close();
//        conn.close();

    }
}
